package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Class;
import com.ruoyi.system.service.IClassService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.ExcelUtil;

/**
 * 班级 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-12-11
 */
@Controller
@RequestMapping("/system/class")
public class ClassController extends BaseController
{
    private String prefix = "system/class";
	
	@Autowired
	private IClassService classService;
	
	@RequiresPermissions("system:class:view")
	@GetMapping()
	public String Class()
	{
	    return prefix + "/class";
	}
	
	/**
	 * 查询班级列表
	 */
	@RequiresPermissions("system:class:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Class sClass)
	{
		startPage();
        List<Class> list = classService.selectClassList(sClass);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出班级列表
	 */
	@RequiresPermissions("system:class:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Class sClass)
    {
    	List<Class> list = classService.selectClassList(sClass);
        ExcelUtil<Class> util = new ExcelUtil<Class>(Class.class);
        return util.exportExcel(list, "class");
    }
	
	/**
	 * 新增班级
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存班级
	 */
	@RequiresPermissions("system:class:add")
	@Log(title = "班级", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Class sClass)
	{		
		return toAjax(classService.insertClass(sClass));
	}

	/**
	 * 修改班级
	 */
	@GetMapping("/edit/{classId}")
	public String edit(@PathVariable("classId") Integer classId, ModelMap mmap)
	{
		Class sClass = classService.selectClassById(classId);
		mmap.put("class", sClass);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存班级
	 */
	@RequiresPermissions("system:class:edit")
	@Log(title = "班级", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Class sClass)
	{		
		return toAjax(classService.updateClass(sClass));
	}
	
	/**
	 * 删除班级
	 */
	@RequiresPermissions("system:class:remove")
	@Log(title = "班级", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(classService.deleteClassByIds(ids));
	}
	
}
